package cn.zn.modules.zzsys.cur.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.zn.framework.common.vo.ComboxItemVO;
import cn.zn.modules.zzsys.cur.entity.SysRole;
import cn.zn.modules.zzsys.cur.mapper.SysRoleMapper;
import cn.zn.modules.zzsys.cur.service.SysRoleService;
import cn.zn.modules.zzsys.inter.SysRoleInter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole>
        implements SysRoleService, SysRoleInter {

    @Override
    public List<ComboxItemVO> queryRoleList(String createUserId, Boolean showSys) {
        boolean myShowSys = false;
        if (showSys != null) {
            myShowSys = showSys;
        }
        return super.list(new QueryWrapper<SysRole>()
                .eq(StrUtil.isNotEmpty(createUserId), "CREATE_USER_ID_", createUserId)
                .eq(!myShowSys, "IS_SYS_", 0))
                .stream().map(o -> ComboxItemVO.builder()
                        .text(o.getName())
                        .value(o.getId())
                        .build()).collect(Collectors.toList());
    }

    @Override
    public String queryRoleName(String roleId) {
        SysRole sysRole = super.getById(roleId);
        if(sysRole == null){
            return "";
        }
        return sysRole.getName();
    }
}




